package com.module.antiFake;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import base.util.Page;

import com.module.antiFake.manager.AntiFakeFileManager;
import com.module.antiFake.manager.AntiFakeReplyManage;
import com.module.antiFake.util.AntiFakeConstant;
import com.module.antiFake.vo.AntiFakeFile;
import com.module.antiFake.vo.AntiFakeReply;
import com.module.sys.LoginSession;

public class AntiFakeReplyService {
	
	/**
	 * 后台列表显示回复信息
	 * @param antiFakeReply
	 * @param start
	 * @param limit
	 * @return
	 * @throws Exception
	 */
	public Page listAntiFakeReply(AntiFakeReply antiFakeReply,final Integer start,final Integer limit)throws Exception{
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		AntiFakeReplyManage replay = AntiFakeReplyManage.getInstance();
		page = replay.listAntiFakeReply(antiFakeReply, page);
		return page;
	}
	/**
	 * 取下一条投诉反馈记录
	 * @param antiFakeReply
	 * @param start
	 * @param limit
	 * @return
	 * @throws Exception
	 */
	public Page getNextAntiFakeReply(AntiFakeReply antiFakeReply,final Integer start,final Integer limit)throws Exception{		
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		antiFakeReply.setOrgId(LoginSession.getOrgid());
		AntiFakeReplyManage replay = AntiFakeReplyManage.getInstance();
		page = replay.getNextAntiFakeReply(antiFakeReply,page);
		return page;
	}	
	/**
	 * 回复投诉
	 * @param antiFakeReply
	 * @return
	 * @throws Exception
	 */
	public Map save(AntiFakeReply antiFakeReply)throws Exception{
		 antiFakeReply.setReplyName(LoginSession.getUsername());
		 antiFakeReply.setOrgId(LoginSession.getOrgid());
		 antiFakeReply.setOrgName(LoginSession.getOrgname());
		 antiFakeReply.setType(1);
		 Map<String,Object> map = new HashMap<String,Object>();
		 AntiFakeReplyManage replay = AntiFakeReplyManage.getInstance();
		 map = replay.addAntiFakeReply(antiFakeReply,AntiFakeConstant.NORMAL_STATE);
		 return map;
	}
	
	/**
	 * 处理完毕 
	 * @param antiFakeReply
	 * @return
	 * @throws Exception
	 */
	public Map disposeof(AntiFakeReply antiFakeReply)throws Exception{
		 antiFakeReply.setReplyName(LoginSession.getUsername());
		 antiFakeReply.setOrgId(LoginSession.getOrgid());
		 antiFakeReply.setOrgName(LoginSession.getOrgname());
		 antiFakeReply.setType(1);	
		 Map<String,Object> map = new HashMap<String,Object>();
		 AntiFakeReplyManage replay = AntiFakeReplyManage.getInstance();
		 map = replay.addAntiFakeReply(antiFakeReply,AntiFakeConstant.END_STATE);
		 return map;
	}
	/**
	 * 下载附件
	 * @param antiFakeReply
	 * @return
	 * @throws Exception
	 */
	public String down(AntiFakeReply antiFakeReply)throws Exception{
		AntiFakeFileManager file = AntiFakeFileManager.getInstance();
		List<AntiFakeFile> listfile =  file.getUrl(antiFakeReply.getFkId());
		StringBuffer sb = new StringBuffer();
    	for(int i=0;i<listfile.size();i++){
    		sb.append(listfile.get(i).getUrl());
    		sb.append(",");
    	}
    	return sb.toString();
	}
}
